import java.io.IOException;
import java.nio.channels.Selector;

/**
 * 服务端线程基础类
 * main reactor和sub reactor 都要实现这个类
 */
public abstract class ServerThread extends Thread {

    protected Selector selector;

    public ServerThread(String name) {
        super(name);
        try {
            // 创建selector
            this.selector = Selector.open();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }


    //关闭selector
    public void closeSelector() {
        try {
            selector.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    //唤醒selector
    public void wakeupSelector() {
        selector.wakeup();
    }


}
